<template>
  <div class="app-container">
    <!-- 导航栏 -->
    <el-card style="margin-bottom: 5px; height: 40px" shadow="always" :body-style="{ padding: '0' }">
      <div style="display: flex; line-height: 37px">
        <h1
          v-for="(item, index) in navItems"
          :key="index"
          :class="{ DynamicCondition: isActive === index, spacing: index > 0 }"
          @click="clickToSwitch(index)"
          style="font-size: 15px; cursor: pointer"
        >
          {{ item }}
        </h1>
      </div>
    </el-card>

    <div v-if="isActive === 0" style="display: flex">
      <div style="width: 29%">
        <h1 style="font-size: 15px">成型生产线资料定义</h1>
        <el-button type="primary" size="default" @click="AddLine">新增</el-button>
        <el-button type="primary" size="default" @click="handleCloseMateriaLKlc">删除</el-button>

        <Table
          @inputChange="confirmChange7"
          :isLoading="isLoading10"
          @currentRow="currentRow2"
          :tableData="lineQueryTableDate"
          :tableHeader="tableHeader1"
          :selection="false"
          :TableHeight="100"
        />
      </div>

      <div style="width: 50%; margin-left: 15px; margin-right: 15px">
        <h1 style="font-size: 15px">生产线日排量定义</h1>
        <Find
          @findClicked="findClicked"
          style="margin-bottom: 5px"
          :searchImg="false"
          @Launchform="Launchform6"
          :OriginalFilter="{ static: true }"
          :formList="formList2"
        />
        <Table
          :isLoading="isLoading7"
          @selectValChange="confirmChange11"
          @inputChange="confirmChange11"
          @currentRow="currentRow"
          :tableData="weekQueryQueryTableDate"
          :tableHeader="tableHeader2"
          :selection="false"
          :TableHeight="100"
        />
        <PageModule
          :PageData="{ total, buttonS: true }"
          :layout="'prev, pager'"
          @pageSizeChange="handleSizeChange"
          @pageChange="handleCurrentChange"
        />
      </div>

      <div style="width: 17%">
        <h1 style="font-size: 15px">参数定义</h1>
        <Find
          @findClicked="findClicked5"
          :searchImg="false"
          @Launchform="Launchform7"
          style="margin-bottom: 20px"
          :OriginalFilter="{ static: true }"
          :formList="formList5"
        />
        <Table @currentRow="currentRow4" :tableData="holidayQueryTableDate" :tableHeader="tableHeader3" :selection="false" :TableHeight="100" />
      </div>
    </div>

    <div v-if="isActive === 1">
      <Find
        @findClicked="findClicked10"
        style="margin-bottom: 5px"
        :searchImg="false"
        @Launchform="Launchform9"
        :OriginalFilter="{ static: true }"
        :formList="formList8"
      />
      <Table
        @inputChange="confirmChange5"
        @selectList="selectList"
        :isLoading="isLoading3"
        :tableData="typeBodyQueryTableDate"
        :tableHeader="tableHeader9"
        :selection="true"
        :TableHeight="100"
      />
      <PageModule
        :PageData="{ total: total1, buttonS: true }"
        :layout="'prev, pager'"
        @pageSizeChange="handleSizeChange1"
        @pageChange="handleCurrentChange1"
      />
    </div>

    <div v-if="isActive === 2">
      <Find
        @findClicked="findClicked11"
        style="margin-bottom: 5px"
        :searchImg="false"
        @Launchform="Launchform10"
        :OriginalFilter="{ static: true }"
        :formList="formList9"
      />
      <Table
        @inputChange="confirmChange6"
        @selectList="selectList1"
        :isLoading="isLoading5"
        :tableData="typeBodyQueryTableDate1"
        :tableHeader="tableHeader10"
        :selection="true"
        :TableHeight="100"
      />
      <PageModule
        :PageData="{ total: total12, buttonS: true }"
        :layout="'prev, pager'"
        @pageSizeChange="handleSizeChange12"
        @pageChange="handleCurrentChange12"
      />
    </div>
  </div>

  <el-dialog v-model="dialogVisible1" width="30%" class="dialog pb0">
    <Find :searchImg="false" @Launchform="Launchform5" style="margin-bottom: 20px" :OriginalFilter="{ static: true }" :formList="formList1" />
    <el-button type="primary" size="default" @click="MoldingLineMethods">确认新增</el-button>
    <el-button type="primary" size="default" @click="dialogVisible1 = false">取消</el-button>
  </el-dialog>

  <el-dialog v-model="dialogVisible2" width="30%" class="dialog pb0">
    <Find :searchImg="false" @Launchform="Launchform7" style="margin-bottom: 20px" :OriginalFilter="{ static: true }" :formList="formList3" />
    <el-button type="primary" size="default" @click="displacementAddMethods">确认新增</el-button>
    <el-button type="primary" size="default" @click="dialogVisible2 = false">取消</el-button>
  </el-dialog>

  <el-dialog v-model="dialogVisible3" width="30%" class="dialog pb0">
    <Find :searchImg="false" @Launchform="Launchform8" style="margin-bottom: 20px" :OriginalFilter="{ static: true }" :formList="formList7" />
    <el-button type="primary" size="default" @click="holidayAddMethods">确认新增</el-button>
    <el-button type="primary" size="default" @click="dialogVisible3 = false">取消</el-button>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import JMessage from '@/utils/JMessage'
import { ElMessage, ElMessageBox } from 'element-plus'
import LoginWork from '@/utils/LoginWork'
export default defineComponent({
  name: 'MoldingArrangement'
})
</script>
<script lang="ts" setup>
import { i18n, Jzhcn } from '@/i18n'
import {
  insertMonth,
  MoldingLine,
  deleteMethods,
  lineQuery,
  displacementQuery,
  displacementDelete,
  displacementAdd,
  holidayQuery,
  lineQuery1,
  holidayAdd,
  holidayDelete,
  typeBodyQuery,
  batchDelete,
  update,
  brandQuery,
  typeBodyQuery1,
  batchDelete1,
  update1,
  brandQuery1
} from '@/api/Control/WEB/MoldingArrangement'

// 时段门槛定义
const tableHeader10 = ref([
  {
    label: '类型',
    prop: 'ltType',
    change: true
  },
  {
    label: '品牌',
    prop: 'brand',
    change: true
  },
  {
    label: '型体',
    prop: 'style',
    change: true
  },
  {
    label: '冲刀试做',
    prop: 'trailLt'
  },
  {
    label: '主面料',
    prop: 'mtlLt'
  },
  {
    label: '冲裁',
    prop: 'cut1Lt'
  },
  {
    label: '工艺',
    prop: 'cut2Lt'
  },
  {
    label: '配套',
    prop: 'cut3Lt'
  },
  {
    label: '针车',
    prop: 'stitchLt'
  },
  {
    label: '大底',
    prop: 'soleLt'
  },
  {
    label: '成型',
    prop: 'lastLt',
    change: true
  },
  {
    label: '建档用户',
    prop: 'userId',
    change: true
  },
  {
    label: '建档日期',
    prop: 'sysDate',
    change: true
  }
])

const formList9 = ref<any>([
  {
    type: 'select',
    selectValue: '',
    selectP: '类型',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '全部',
        optionLabel: '全部'
      },
      {
        optionKey: 2,
        optionValue: '通用',
        optionLabel: '通用'
      },
      {
        optionKey: 3,
        optionValue: '按品牌',
        optionLabel: '按品牌'
      },
      {
        optionKey: 4,
        optionValue: '按型体',
        optionLabel: '按型体'
      }
    ]
  },

  {
    type: 'input',
    inputPlaceholder: '品牌',
    inputValue: ''
  },

  {
    type: 'input',
    inputPlaceholder: '型体',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '搜索',
    bgColor: 'rgb(239, 187, 36)'
  },
  {
    type: 'button',
    checkboxLabel: '置空'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '更新型体门槛'
  },
  {
    type: 'button',
    checkboxLabel: '按品牌更新'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])

const confirmChange11 = async (row: any) => {
  row.line = row.line.selectValue
  const result = await LoginWork.put<any, any>(`/LastConfig/percent/up`, row)
  if (result.code === 200) {
    weekQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 生产线修改
const confirmChange7 = async (row?: any) => {
  const result = await LoginWork.put<any, any>(`/LastConfig/line/up?workShopOld=${row.workshop}`, row)
  if (result.code === 200) {
    lineQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 修改
const confirmChange6 = async (row?: any) => {
  const result = await LoginWork.post<any, any>('/LastConfig/time/update', row)
  if (result.code === 200) {
    typeBodyQueryMethods1()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

const batchDeleteParms1 = ref([])

// 品牌查询
const brandQueryMethods1 = async () => {
  try {
    const result = await brandQuery1()
    formList9.value[5].selectOptions = EvaluatesTheArrayReturnValue(result)
  } catch (error) {
    ElMessage.error('品牌查询出错')
  }
}

// 型体品牌更新
const updateMethodsParms1 = ref<any>({
  brand: '',
  type: ''
})

const updateMethods1 = async () => {
  try {
    const result = await update1(updateMethodsParms1.value)
    if (result.code === 200) {
      typeBodyQueryMethods1()
      ElMessage.success('更新成功')
    } else {
      ElMessage.error('更新失败')
    }
  } catch (error) {
    ElMessage.error('更新失败')
  }
}

// 型体材料批量删除
const selectList1 = (row: any) => {
  batchDeleteParms1.value = row.map((item: any) => item.id)
}

const handleCloseMateriaLKlc5 = (_done?: () => void) => {
  if (batchDeleteParms1.value.length === 0) {
    JMessage.warning('请勾选需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        batchDeleteMethods1()
      })
      .catch(() => {})
  }
}

const batchDeleteMethods1 = async () => {
  try {
    const result = await batchDelete1(batchDeleteParms1.value)
    if (result.code === 200) {
      typeBodyQueryMethods1()
      ElMessage.success('删除成功')
    } else {
      ElMessage.error('删除失败')
    }
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

const typeBodyQueryParms12 = ref({
  type: '',
  brand: '',
  style: ''
})

const Launchform10 = (row: any) => {
  updateMethodsParms1.value.brand = row[5].selectValue
  typeBodyQueryParms12.value.type = row[0].selectValue
  typeBodyQueryParms12.value.brand = row[1].inputValue
  typeBodyQueryParms12.value.style = row[2].inputValue
}

const findClicked11 = (row: any) => {
  if (row === '删除') {
    handleCloseMateriaLKlc5()
  }

  if (row === '更新型体门槛') {
    updateMethodsParms1.value.type = 2
    updateMethods1()
  }

  if (row === '按品牌更新') {
    updateMethodsParms1.value.type = 1
    if (updateMethodsParms1.value.brand === '') {
      ElMessage.warning('请选择品牌')
      return
    }
    updateMethods1()
  }

  if (row === '搜索') {
    typeBodyQueryMethods1()
  }

  if (row === '置空') {
    formList9.value[0].selectValue = ''
    formList9.value[1].inputValue = ''
    formList9.value[2].inputValue = ''
    typeBodyQueryMethods()
  }
}

// 型体产能查询
const lineQueryParms1 = ref<any>({
  pageNum: 1,
  pageSize: 40
})

const total12 = ref(0)

const handleSizeChange12 = (val: number) => {
  lineQueryParms1.value.pageSize = val
  typeBodyQueryMethods1()
}
const handleCurrentChange12 = (val: number) => {
  lineQueryParms1.value.pageNum = val
  typeBodyQueryMethods1()
}

const typeBodyQueryTableDate1 = ref([])

const isLoading5 = ref(false)

const typeBodyQueryMethods1 = async () => {
  isLoading5.value = true
  try {
    const result = await typeBodyQuery1(lineQueryParms1.value, typeBodyQueryParms12.value)
    typeBodyQueryTableDate1.value = result.list.map((item: any) => {
      item.change = 'Y'
      item.disableConfirm = true
      return item
    })
    total12.value = result.total
    isLoading5.value = false
  } catch (error) {
    ElMessage.error('型体查询出错')
  }

  isLoading5.value = false
}

const formList8 = ref<any>([
  {
    type: 'select',
    selectValue: '',
    selectP: '类型',
    selectOptions: [
      {
        optionKey: 1,
        optionValue: '全部',
        optionLabel: '全部'
      },
      {
        optionKey: 2,
        optionValue: '通用',
        optionLabel: '通用'
      },
      {
        optionKey: 3,
        optionValue: '按品牌',
        optionLabel: '按品牌'
      },
      {
        optionKey: 4,
        optionValue: '按型体',
        optionLabel: '按型体'
      }
    ]
  },

  {
    type: 'input',
    inputPlaceholder: '品牌',
    inputValue: ''
  },

  {
    type: 'input',
    inputPlaceholder: '型体',
    inputValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '搜索',
    bgColor: 'rgb(239, 187, 36)'
  },
  {
    type: 'button',
    checkboxLabel: '置空'
  },
  {
    type: 'select',
    selectValue: '',
    selectP: '品牌',
    selectOptions: []
  },
  {
    type: 'button',
    checkboxLabel: '更新型体IE'
  },
  {
    type: 'button',
    checkboxLabel: '按品牌更新'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])

const tableHeader9 = ref([
  {
    label: '类型',
    prop: 'ieType',
    change: true
  },
  {
    label: '品牌',
    prop: 'brand',
    change: true
  },
  {
    label: '型体',
    prop: 'style',
    change: true
  },
  {
    label: '线别日产能(双)',
    prop: 'ieQty'
  },
  {
    label: '人均日产能(双)',
    prop: 'ppdQty'
  },
  {
    label: '建档用户',
    prop: 'userId',
    change: true
  },
  {
    label: '建档日期',
    prop: 'sysDate',
    change: true
  }
])

// 修改
const confirmChange5 = async (row?: any) => {
  const result = await LoginWork.post<any, any>('/LastConfig/ie/update', row)
  if (result.code === 200) {
    typeBodyQueryMethods()
    JMessage.success(result.message)
  } else {
    JMessage.error(result.message)
  }
}

// 品牌查询
const brandQueryMethods = async () => {
  try {
    const result = await brandQuery()
    formList8.value[5].selectOptions = EvaluatesTheArrayReturnValue(result)
  } catch (error) {
    ElMessage.error('品牌查询出错')
  }
}

// 型体品牌更新
const updateMethodsParms = ref<any>({
  brand: '',
  type: ''
})

const updateMethods = async () => {
  try {
    const result = await update(updateMethodsParms.value)
    if (result.code === 200) {
      typeBodyQueryMethods()
      ElMessage.success('更新成功')
    } else {
      ElMessage.error('更新失败')
    }
  } catch (error) {
    ElMessage.error('更新失败')
  }
}

// 型体材料批量删除
const selectList = (row: any) => {
  batchDeleteParms.value = row.map((item: any) => item.id)
}

const batchDeleteParms = ref([])

const findClicked10 = (row: any) => {
  if (row === '删除') {
    handleCloseMateriaLKlc3()
  }

  if (row === '更新型体IE') {
    updateMethodsParms.value.type = 2
    updateMethods()
  }

  if (row === '按品牌更新') {
    updateMethodsParms.value.type = 1
    if (updateMethodsParms.value.brand === '') {
      ElMessage.warning('请选择品牌')
      return
    }
    updateMethods()
  }

  if (row === '搜索') {
    typeBodyQueryMethods()
  }

  if (row === '置空') {
    formList8.value[0].selectValue = ''
    formList8.value[1].inputValue = ''
    formList8.value[2].inputValue = ''
    typeBodyQueryMethods()
  }
}

const handleCloseMateriaLKlc3 = (_done?: () => void) => {
  if (batchDeleteParms.value.length === 0) {
    JMessage.warning('请勾选需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        batchDeleteMethods()
      })
      .catch(() => {})
  }
}

const batchDeleteMethods = async () => {
  try {
    const result = await batchDelete(batchDeleteParms.value)
    if (result.code === 200) {
      typeBodyQueryMethods()
      ElMessage.success('删除成功')
    } else {
      ElMessage.error('删除失败')
    }
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

// 型体产能查询
const lineQueryParms = ref<any>({
  pageNum: 1,
  pageSize: 40
})

const total1 = ref(0)
const handleSizeChange1 = (val: number) => {
  lineQueryParms.value.pageSize = val
  typeBodyQueryMethods()
}
const handleCurrentChange1 = (val: number) => {
  lineQueryParms.value.pageNum = val
  typeBodyQueryMethods()
}

const Launchform9 = (row: any) => {
  updateMethodsParms.value.brand = row[5].selectValue
  typeBodyQueryParms1.value.type = row[0].selectValue
  typeBodyQueryParms1.value.brand = row[1].inputValue
  typeBodyQueryParms1.value.style = row[2].inputValue
}

const typeBodyQueryParms1 = ref({
  type: '',
  brand: '',
  style: ''
})

const isLoading3 = ref(false)

const typeBodyQueryTableDate = ref([])

const typeBodyQueryMethods = async () => {
  isLoading3.value = true
  try {
    const result = await typeBodyQuery(lineQueryParms.value, typeBodyQueryParms1.value)
    typeBodyQueryTableDate.value = result.list.map((item: any) => {
      item.change = 'Y'
      item.disableConfirm = true
      return item
    })
    total1.value = result.total
    isLoading3.value = false
  } catch (error) {
    ElMessage.error('型体查询出错')
  }

  isLoading3.value = false
}

// 节假日删除
const holidayDeleteParms = ref('')

const currentRow4 = (row: any) => {
  holidayDeleteParms.value = row.holidayDate
}

const handleCloseMateriaLKlc2 = (_done?: () => void) => {
  if (holidayDeleteParms.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        holidayDeleteMethods()
      })
      .catch(() => {})
  }
}

const holidayDeleteMethods = async () => {
  try {
    const result = await holidayDelete(holidayDeleteParms.value)
    if (result.code === 200) {
      holidayQueryMethods()
      ElMessage.success('删除成功')
    } else {
      ElMessage.error('删除失败')
    }
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

// 节假日新增
const dialogVisible3 = ref(false)

const Launchform8 = (row: any) => {
  holidayAddParms.value.holidayDate = row[0].dateValue
}

const findClicked5 = (row: string) => {
  if (row === '新增') {
    dialogVisible3.value = true
  }
  if (row === '删除') {
    handleCloseMateriaLKlc2()
  }
}

const holidayAddParms = ref({
  holidayDate: ''
})

const holidayAddMethods = async () => {
  if (holidayAddParms.value.holidayDate === '') {
    ElMessage.warning('请选择节假日')
    return
  }
  try {
    const result = await holidayAdd(holidayAddParms.value)
    if (result.code === 200) {
      holidayQueryMethods()
      dialogVisible3.value = false
      ElMessage.success('新增成功')
    } else {
      ElMessage.error('新增失败')
    }
  } catch (error) {
    ElMessage.error('新增失败')
  }
}

// 产线查询
const listTableDate = ref([])

const lineQuery1Methods = async () => {
  try {
    const result = await lineQuery1()
    let NewArray: never[] = []
    NewArray = result.data.reduce((arr: any, item: any) => {
      // 只添加非空的 typeName 和 typeNo
      arr.push(item.line)
      return arr
    }, [])
    formList2.value[0].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
    formList3.value[0].selectOptions = EvaluatesTheArrayReturnValue(NewArray)
    listTableDate.value = EvaluatesTheArrayReturnValue1(NewArray)
  } catch (error) {
    ElMessage.error('产线下拉框数据查询出错')
  }
}

const EvaluatesTheArrayReturnValue1 = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      value: item,
      label: item
    }
  })
}

const EvaluatesTheArrayReturnValue = (ArrayList: any) => {
  return ArrayList.map((item: any, index: any) => {
    return {
      optionKey: index,
      optionValue: item,
      optionLabel: item
    }
  })
}

// 参数定义查询
const holidayQueryParms = ref({
  pageNum: '',
  pageSize: ''
})

const formList5 = ref<any>([
  {
    type: 'radio1',
    checkboxLabel: '线别日产能',
    label: '0'
  },
  {
    type: 'radio1',
    checkboxLabel: '人均日产能',
    label: '1'
  },
  {
    type: 'button',
    checkboxLabel: '新增'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])

const holidayQueryTableDate = ref([])

const holidayQueryMethods = async () => {
  try {
    const result = await holidayQuery(holidayQueryParms.value)
    if (result.code === 200) {
      holidayQueryTableDate.value = result.data.dtos
    } else {
      ElMessage.error('查询参数失败')
    }
  } catch (error) {
    ElMessage.error('查询参数失败')
  }
}

// 排量新增
const displacementAddParms = ref({
  ddate: '',
  id: '',
  line: '',
  percent: ''
})

const Launchform7 = (row: any) => {
  displacementAddParms.value.line = row[0].selectValue
  displacementAddParms.value.ddate = row[1].dateValue
  displacementAddParms.value.percent = row[2].inputValue
}

const displacementAddMethods = async () => {
  try {
    const result = await displacementAdd(displacementAddParms.value)
    if (result.code === 200) {
      weekQueryMethods()
      dialogVisible2.value = false
      ElMessage.success('新增成功')
    } else {
      ElMessage.error('新增失败')
    }
  } catch (error) {
    ElMessage.error('新增失败')
  }
}

// 排量删除
const displacementDeleteParms = ref('')

const dialogVisible2 = ref(false)

const findClicked = (row: string) => {
  if (row === '删除') {
    handleCloseMateriaLKlc1()
  }

  if (row === '新增') {
    dialogVisible2.value = true
  }

  if (row === '置空') {
    formList2.value[0].selectValue = ''
    formList2.value[1].dateValue = ''
    formList2.value[2].dateValue = ''
  }
  if (row === '插入月日排量资料') {
    if (insertMonthParms.value === '') {
      return ElMessage.warning('请先选择月份')
    }
    insertMonthMethods()
  }
}

const insertMonthParms = ref('')

const insertMonthMethods = async () => {
  insertMonthParms.value = insertMonthParms.value.replace(/-/g, '')
  try {
    const result = await insertMonth(insertMonthParms.value)
    if (result.code === 200) {
      weekQueryMethods()
      ElMessage.success('插入成功')
    } else {
      ElMessage.error('插入失败')
    }
  } catch (error) {
    ElMessage.warning('插入失败')
  }
}

const currentRow = (row: any) => {
  displacementDeleteParms.value = row.id
}

const handleCloseMateriaLKlc1 = (_done?: () => void) => {
  if (displacementDeleteParms.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        displacementDeleteMethods()
      })
      .catch(() => {})
  }
}

const displacementDeleteMethods = async () => {
  try {
    const result = await displacementDelete(displacementDeleteParms.value)
    if (result.code === 200) {
      weekQueryMethods()
      ElMessage.success('删除成功')
    } else {
      ElMessage.error('删除失败')
    }
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

// 排量查询
const weekQueryQueryTableDate = ref<any>([])

const displacementQueryParms = ref({
  pageNum: 1,
  pageSize: 40
})

const displacementQueryParms1 = ref({
  line: '',
  time: ''
})

const Launchform6 = (row: any) => {
  insertMonthParms.value = row[2].dateValue
  displacementQueryParms1.value.line = row[0].selectValue
  displacementQueryParms1.value.time = row[1].dateValue
  weekQueryMethods()
}

const total = ref(0)
const handleSizeChange = (val: number) => {
  displacementQueryParms.value.pageSize = val
  weekQueryMethods()
}
const handleCurrentChange = (val: number) => {
  displacementQueryParms.value.pageNum = val
  weekQueryMethods()
}

const isLoading7 = ref(false)

const weekQueryMethods = async () => {
  isLoading7.value = true
  try {
    const result = await displacementQuery(displacementQueryParms.value, displacementQueryParms1.value)
    weekQueryQueryTableDate.value = result.dtos.map((item: any) => {
      item.line = {
        selectValue: item.line || '',
        options: listTableDate
      }
      item.change = 'Y'
      item.disableConfirm = true
      return item
    })
    total.value = result.total
  } catch (error) {
    ElMessage.error('查询生产线失败')
  }
  isLoading7.value = false
}

const formList2 = ref<any>([
  {
    type: 'select',
    selectValue: '',
    selectP: '生产线',
    selectOptions: []
  },

  {
    type: 'dateSingle',
    dateLabel: '交期',
    dateValue: ''
  },

  {
    dateType: 'month',
    type: 'dateMonth2',
    placeholder: '月份',
    dateLabel: '',
    dateValue: ''
  },
  {
    type: 'button',
    checkboxLabel: '插入月日排量资料'
  },
  {
    type: 'button',
    checkboxLabel: '置空'
  },
  {
    type: 'button',
    checkboxLabel: '新增'
  },
  {
    type: 'button',
    checkboxLabel: '删除'
  }
])

const isLoading10 = ref(false)

// 产线查询
const lineQueryTableDate = ref<any>([])

const lineQueryMethods = async () => {
  isLoading10.value = true
  try {
    const result = await lineQuery()
    lineQueryTableDate.value = result.data.map((item: any) => {
      item.change = 'Y'
      item.disableConfirm = true
      return item
    })
  } catch (error) {
    ElMessage.error('查询生产线失败')
  }
  isLoading10.value = false
}

onMounted(() => {
  lineQueryMethods()

  weekQueryMethods()

  holidayQueryMethods()

  lineQuery1Methods()

  brandQueryMethods()

  brandQueryMethods1()
})

// 生产线删除
const deleteMethodsParms = ref('')

const currentRow2 = (row: any) => {
  deleteMethodsParms.value = row.workshop
}

const handleCloseMateriaLKlc = (_done?: () => void) => {
  if (deleteMethodsParms.value === '') {
    JMessage.warning('请选择需要删除的数据')
  } else {
    ElMessageBox.confirm('确认要删除数据吗?')
      .then(async () => {
        deleteMethodsMethods()
      })
      .catch(() => {})
  }
}

const deleteMethodsMethods = async () => {
  try {
    const result = await deleteMethods(deleteMethodsParms.value)
    if (result.code === 200) {
      ElMessage.success('删除成功')
      lineQueryMethods()
    } else {
      ElMessage.error('删除失败')
    }
  } catch (error) {
    ElMessage.error('删除失败')
  }
}

const dialogVisible1 = ref(false)

const AddLine = () => {
  dialogVisible1.value = true
}

const Launchform5 = (data: any) => {
  MoldingLineParms.value.seqNo = data[0].inputValue
  MoldingLineParms.value.workshop = data[1].inputValue
  MoldingLineParms.value.line = data[2].inputValue
  MoldingLineParms.value.workshopName = data[3].inputValue
  MoldingLineParms.value.ieQty = data[4].inputValue
  MoldingLineParms.value.persons = data[5].inputValue
}

// 产线新增
const MoldingLineParms = ref({
  ieQty: '',
  line: '',
  persons: '',
  ppdQty: '',
  seqNo: '',
  workshop: '',
  workshopName: ''
})

const MoldingLineMethods = async () => {
  if (
    MoldingLineParms.value.seqNo === '' ||
    MoldingLineParms.value.line === '' ||
    MoldingLineParms.value.workshop === '' ||
    MoldingLineParms.value.workshopName === '' ||
    MoldingLineParms.value.ieQty === '' ||
    MoldingLineParms.value.persons === ''
  ) {
    return ElMessage.error('请将信息填写完整')
  }
  try {
    const result = await MoldingLine(MoldingLineParms.value)
    if (result.code === 200) {
      lineQueryMethods()
      dialogVisible1.value = false
      ElMessage.success('新增成功')
    } else {
      ElMessage.error('新增失败')
    }
  } catch (error) {
    ElMessage.error('新增失败')
  }
}

const formList1 = ref<any>([
  {
    type: 'input',
    inputPlaceholder: '序号',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '车间代码',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '车间名称',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '生产线名称',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '日产能(双)',
    inputValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '人数',
    inputValue: ''
  }
])

const formList3 = ref<any>([
  {
    type: 'select',
    selectValue: '',
    selectP: '生产线',
    selectLabel: '部门',
    selectOptions: []
  },
  {
    type: 'dateSingle',
    dateLabel: '日期',
    dateValue: ''
  },
  {
    type: 'input',
    inputPlaceholder: '排量',
    inputValue: ''
  }
])

const formList7 = ref<any>([
  {
    type: 'dateSingle',
    dateLabel: '日期',
    dateValue: ''
  }
])

const tableHeader1 = ref([
  {
    label: '序号',
    prop: 'seqNo'
  },
  {
    label: '车间代码',
    prop: 'workshop'
  },
  {
    label: '车间名称',
    prop: 'line'
  },
  {
    label: '生产线名称',
    prop: 'workshopName'
  },
  {
    label: '日产能(双)',
    prop: 'ieQty'
  },
  {
    label: '人数',
    prop: 'persons'
  }
])

const tableHeader2 = ref([
  {
    label: '生产线',
    prop: 'line',
    type: 'select'
  },
  {
    label: '日期',
    prop: 'ddate',
    type: 'dateSingle'
  },
  {
    label: '排量',
    prop: 'percent'
  }
])
const tableHeader3 = ref([
  {
    label: '日期',
    prop: 'holidayDate'
  }
])

// 导航栏
const navItems = ref(['基础资料设定', '型体产能设定', '时段门槛设定'])

// 导航栏状态
const isActive = ref(0)

//点击切换
const clickToSwitch = (index: number) => {
  if (index === 2) {
    typeBodyQueryMethods1()
  }
  if (index === 1) {
    typeBodyQueryMethods()
  }
  isActive.value = index
}
</script>

<style lang="less" scoped>
.H1Size {
  font-size: 16px;
}

.bottom {
  float: right;
}

.DynamicCondition {
  color: #f89027;
  border-bottom: 2px solid #f89027;
}

.spacing {
  margin-left: 15px;
  /* 根据需要调整间距大小 */
}

// 底部
.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 40px;
  width: 100%;

  .total {
    font-size: 14px;
    color: rgba(0, 0, 0, 0.6);
    font-family: PingFangSC-Regular-, PingFangSC-Regular;
  }

  :deep(.el-input__wrapper) {
    padding: 0;
  }

  :deep(.el-input__suffix) {
    transform: translateX(-9px);
  }

  :deep(.el-pagination .el-select .el-input) {
    width: 88px;
  }

  :deep(.number) {
    border: 1px solid #dcdcdc;
    margin-right: 8px;
    border-radius: 3px 3px 3px 3px;
  }

  :deep(.is-active.number) {
    background-color: #f89027 !important;
    color: white;
    border-radius: 3px 3px 3px 3px;
  }
}

.ProductionDynamicMainCardMainL {
  display: flex;
}

.save {
  color: black;
  border: 1px solid #e7e7e7;
  background: #e7e7e7;
}

.MainLeftCardH1 {
  font-size: 17px;
}

.table1 {
  :deep(th:nth-child(8)) {
    color: blue !important;
  }

  :deep(th:nth-child(6)) {
    color: blue !important;
  }

  :deep(th:nth-child(5)) {
    color: blue !important;
  }

  :deep(th:nth-child(7)) {
    color: blue !important;
  }
}
</style>
